package ga.report;

import java.util.ArrayList;
import java.util.List;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

@SuppressWarnings("serial")
public class XYChart extends ApplicationFrame {

    public XYChart(final String title, List<Data> dataItems, String xLabel, String yLabel) {

        super(title);
        final XYSeries series = new XYSeries(title);
        for (Data d: dataItems) {
        	series.add(d.getX(), d.getY());
        }

        final XYSeriesCollection data = new XYSeriesCollection(series);
        final JFreeChart chart = ChartFactory.createXYLineChart(
            title,
            xLabel, 
            yLabel, 
            data,
            PlotOrientation.VERTICAL,
            true,
            true,
            false
        );

        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
        setContentPane(chartPanel);

    }

    
    public void makeChart() {
    	pack();
        RefineryUtilities.centerFrameOnScreen(this);
        setVisible(true);
    }
    
    
    public static void main(final String[] args) {
    	List<Data> data = new ArrayList<Data>();
    	for (int i=0; i<100; i++) {
    		data.add(new Data(i, i*i));
    	}

    	final XYChart demo = new XYChart("XY Series Demo", data, "x", "y");
        demo.makeChart();

    }

}